//package com.beidu.lottery.call.consumer;
//
//import com.alibaba.fastjson.JSONObject;
//import com.beidu.lottery.call.constant.MQTopicsConst;
//import com.beidu.lottery.call.entity.PortalActivityRule;
//import com.beidu.lottery.call.entity.dto.ActivityVoteDTO;
//import com.beidu.lottery.call.service.portal.ActivityVoteService;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.kafka.clients.consumer.ConsumerRecord;
//import org.springframework.kafka.annotation.KafkaListener;
//import org.springframework.kafka.support.Acknowledgment;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.Resource;
//
///**
// * <p>
// * 投票活动 消费类
// * </p>
// *
// * @author 北渡
// * @since 2024-08-30
// */
//@Slf4j
//@Component
//public class ActivityVoteConsumer extends ActivityBaseConsumer {
//
//    @Resource
//    private ActivityVoteService activityVoteService;
//
//    /**
//     * 投票消息监听
//     *
//     * @param record 数据
//     * @author 北渡
//     */
//    @KafkaListener(topics = MQTopicsConst.ACTIVITY_VOTE_SUBMIT)
//    public void voteSubmit(ConsumerRecord<String, String> record, Acknowledgment ack) {
//        long startTime = System.currentTimeMillis();
//        log.info("开始消费投票数据, value => {}", record.value());
//        // 转换对象
//        JSONObject data = JSONObject.parseObject(record.value());
//        ActivityVoteDTO dto = data.getObject("dto", ActivityVoteDTO.class);// 投票数据
//        PortalActivityRule rule = data.getObject("rule", PortalActivityRule.class);// 投票规则
//        // 幂等校验
//        if (super.isIdempotent(dto.getMessageId())) {
//            ack.acknowledge();// 确认消费成功
//            log.info("投票数据重复消费, messageId => {}", dto.getMessageId());
//            return;
//        }
//        // 用户信息上下文
//        super.setContext(dto);
//        // 投票数据提交
//        boolean isSuccess;
//        try {
//            activityVoteService.voteSubmit(dto, rule);
//            isSuccess = true;
//        } catch (Exception e) {
//            log.error(e.getMessage(), e);
//            isSuccess = false;
//        }
//        // 保存或更新MQ消费记录
//        super.saveOrUpdate(MQTopicsConst.ACTIVITY_VOTE_SUBMIT, data, isSuccess);
//        // 确认消费成功
//        if (isSuccess) ack.acknowledge();
//        log.info("投票数据消费完成, messageId => {}, 耗时：{}毫秒", dto.getMessageId(), System.currentTimeMillis() - startTime);
//    }
//
//}
